package com.dkd.testRank.controller;


import com.dkd.common.core.controller.BaseController;
import com.dkd.common.core.domain.AjaxResult;
import com.dkd.common.core.domain.R;
import com.dkd.common.core.page.TableDataInfo;
import com.dkd.testRank.domain.TestRank;
import com.dkd.testRank.service.ITestRankService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * rank排行 前端控制器
 * </p>
 *
 * @author zwy
 * @since 2025-05-19
 */
@Api(tags = "rank排行")
@RestController
@RequestMapping("/testRank")
public class TestRankController extends BaseController {
    @Autowired
    private ITestRankService rankService;

    /**
     * 查询用户列表
     */
    @ApiOperation("查询rank列表")
    @PreAuthorize("@ss.hasPermi('testRank:rank:list')")
    @GetMapping("/list")
    public TableDataInfo list(TestRank testRank) {
        startPage();
        return getDataTable(rankService.selectList(testRank));
    }

    /**
     * 详情
     *
     * @param id
     * @return 写入了redis
     */
    @ApiOperation("查询rank详情")
    @PreAuthorize("@ss.hasPermi('testRank:rank:query')")
    @GetMapping(value = "/{id}")
    public R<TestRank> getInfo(@PathVariable("id") Integer id) {
        return R.ok(rankService.selectById(id));
    }

    /**
     * 新增rank以及相关信息
     */
    @ApiOperation("新增rank以及相关信息")
    @PreAuthorize("@ss.hasPermi('testRank:rank:add')")
    @PostMapping
    public AjaxResult insertTestRank(@RequestBody TestRank testRank) {
        return AjaxResult.success(rankService.insertTestRank(testRank));
    }

    /**
     * 批量删除rank以及相关信息
     *
     * @param ids 需要删除的rank ID数组
     * @return 删除操作的结果
     */
    @ApiOperation("批量删除rank以及相关信息")
    @PreAuthorize("@ss.hasPermi('testRank:rank:remove')")
    @DeleteMapping("/{ids}")
    public AjaxResult deleteTestRank(@PathVariable Integer[] ids) {
        return AjaxResult.success(rankService.deleteTestRanks(ids));
    }


    /**
     * 修改测试排名及相关信息的接口方法
     *
     * @param testRank 通过请求体接收的TestRank对象，包含要修改的测试排名及相关信息
     * @return 返回AjaxResult对象，用于封装操作结果
     */
    @ApiOperation("修改rank以及相关信息")
    @PreAuthorize("@ss.hasPermi('testRank:rank:edit')")
    @PutMapping
    public AjaxResult updateTestRank(@RequestBody TestRank testRank) {
        return AjaxResult.success(rankService.updateTestRank(testRank));
    }

}
